package org.hu.service;

import org.hu.mapper.DepartmentMapper;
import org.hu.model.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    public Department getDepById(Integer id) {
        return departmentMapper.getDepById(id);
    }

    /**
     *
     * 查询所有部门
     * @return List<Department>
     */
    public List<Department> getAllDeps() {
        return departmentMapper.getAllDeps();
    }

    /**
     * 添加部门
     * @param depname 部门名称
     * @return Integer 1为成功 -1为部门已存在
     */
    public Integer addDep(String depname) {
        if(departmentMapper.getDepByName(depname)!=null) return -1;
        return departmentMapper.addDep(depname);
    }

    /**
     * 删除部门
     * @param depid 部门名称
     * @return Integer 1为成功
     */
    public Integer Deldep(Integer depid) {
        return departmentMapper.delDepById(depid);
    }

    /**
     * 更新部门信息
     * @param id   部门id
     * @param name 部门名称
     * @return Integer 1为成功
     */
    public Integer updatedep(Integer id, String name) {
        return departmentMapper.updatedep(id,name);
    }
}
